<template>
  <div class="detailPageCss">
    <div class="titleCss">教育培训</div>
    <div class="bodyCss">
      <el-tabs v-model="activeName" type="card">
        <el-tab-pane label="岗前培训" name="1">
          <TabTable
            @goToApproalBtn="goToApproalBtn"
            :tableData="tableData"
            :loading="loading"
          />
        </el-tab-pane>
        <el-tab-pane label="岗中培训" name="2">
          <TabTable
            @goToApproalBtn="goToApproalBtn"
            :tableData="tableData"
            :loading="loading"
          />
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="bottomBtnCss">
      <el-button @click="goBackBtn">返回</el-button>
    </div>
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      @close="dialogVisible = false"
    >
      <span>是否通过</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="edit(false)">否</el-button>
        <el-button type="primary" @click="edit(true)">是</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import TabTable from "./components/tabTable/index.vue";
import {
  enterpriseeducationtrain,
  enterpriseeducationtrainEdit,
} from "@/api/zhangping/zpEnterpriseInfo";
export default {
  components: { TabTable },
  props: {
    pageType: {
      type: Number,
      default: () => 0,
    },
  },
  data() {
    return {
      activeName: "1",
      tableData: [],
      loading: false,
      beforPageNum: 1,
      beforePageSize: 10,
      onPageNum: 1,
      onPageSize: 10,
      notPass: false,
      dialogVisible: false,
      id: "",
    };
  },
  created() {
    //  this.getList(1);
  },
  watch: {
    activeName: {
      handler(newVal, oldVal) {
        if (newVal !== oldVal) {
           this.getList(newVal)
        }
      },
      immediate: true,
    },
  },
  methods: {
    async getList(type) {
      console.log("获取列表");

      this.loading = true;
      let res = await enterpriseeducationtrain({
        creditCode: this.$route.query.id,
        trainType: type,
      });
      if (res.code == 200) {
        this.loading = false;
        this.tableData = res.rows;
      }
    },
    goBackBtn() {
      this.$router.back();
    },
    goToApproalBtn(row) {
      this.id = row.id;
      this.dialogVisible = true;
    },
    async edit(notPass) {
      let res = await enterpriseeducationtrainEdit({
        notPass: notPass,
        id: this.id,
      });
      console.log("res", res);
      if(res.code == 200){
        Message.success('操作成功')
      }else {
        Message.error(res.msg)
      }
      this.dialogVisible = false;
    },
  },
};
</script>

<style lang="scss" scoped>
.detailPageCss {
  overflow: hidden;
  position: relative;
  background-color: #fff;
  padding: 20px;
  border-radius: 10px;
  height: calc(100vh - 66px - 40px);
  display: flex;
  flex-direction: column;
  .titleCss {
    text-align: center;
    font-size: 18px;
    font-weight: bold;
  }
  .bodyCss {
    margin-top: 10px;
    width: calc(100% - 40px);
    margin-left: 10px;
    height: calc(100% - 80px);
    overflow-y: auto;
    padding-bottom: 10px;
  }
  .bottomBtnCss {
    margin-top: auto;
    text-align: right;
  }
}
</style>
